﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<volva.Models.Station>" %>
<%@ Import Namespace="volva.Models" %>
<%@ Import Namespace="volva.Services" %>

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">

    <h1><%=Html.Encode(Model.name) %></h1>
    
    <%
        int rating = 0;
        if (Model.ratingCount > 0)
            rating = (int)Math.Round((decimal)(Model.ratingSum / Model.ratingCount));

        Video currentVideo = ViewData["CurrentShow"] as Video;
    %>
    

    <div id="video">
	<div id="embeddedVideo">
	<object width="640" height="360"><param name="movie" value="http://www.youtube.com/v/<%= (currentVideo == null ? "" : currentVideo.embeddCode) %>&hl=en_US&fs=1&"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/<%= (currentVideo == null ? "" : currentVideo.embeddCode) %>&hl=en_US&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="360"></embed></object>
	</div>
<div id="toolbar" class="clearfix">
	    <div id="rate" class="hoverpop">
		<a href="#" class="hover">Einkunn</a>
		<div class="popdown">
		    <a href="/Station/GiveVideoRating/?videoId=<%= (currentVideo == null ? "#" : currentVideo.id.ToString()) %>&rating=1" class="<%= (rating >= 1 ? "starfull" : "staropen") %>" title="Gefa þættinum 1 stjörnu"></a>
		    <a href="/Station/GiveVideoRating/?videoId=<%= (currentVideo == null ? "#" : currentVideo.id.ToString()) %>&rating=2" class="<%= (rating >= 2 ? "starfull" : "staropen") %>" title="Gefa þættinum 2 stjörnur"></a>
		    <a href="/Station/GiveVideoRating/?videoId=<%= (currentVideo == null ? "#" : currentVideo.id.ToString()) %>&rating=3" class="<%= (rating >= 3 ? "starfull" : "staropen") %>" title="Gefa þættinum 3 stjörnur"></a>
		    <a href="/Station/GiveVideoRating/?videoId=<%= (currentVideo == null ? "#" : currentVideo.id.ToString()) %>&rating=4" class="<%= (rating >= 4 ? "starfull" : "staropen") %>" title="Gefa þættinum 4 stjörnur"></a>
		    <a href="/Station/GiveVideoRating/?videoId=<%= (currentVideo == null ? "#" : currentVideo.id.ToString()) %>&rating=5" class="<%= (rating == 5 ? "starfull" : "staropen") %>" title="Gefa þættinum 5 stjörnur"></a><br clear="all" />
		    <span class="text"><%= rating %> af 5</span>
		</div>
	    </div>
	    <div id="bookmark">
		<a href="javascript:if(document.all)window.external.AddFavorite(location.href,document.title);else%20if(window.sidebar)window.sidebar.addPanel(document.title,location.href,'');" class="hover">Bókmerkja</a>
	    </div>
	    <div id="mailinglist" class="hoverpop">
		<a href="#" class="hover">Póstlisti</a>
	    </div>
	    <%
	     WebUser user = ViewData["user"] as WebUser;
         if (User.Identity.IsAuthenticated)
         {
             foreach (WebUserRole role in user.WebUserRoles)
             {
                 if (role.access >= 1 && role.Station_id == Model.id)
                 {
                     Response.Write("<div id='createschedule' class='hoverpop'>" +
                                    "<a href='/Station/Schedule/" + Model.id + "' class='hover'>Breyta dagsskrá</a>" +
                                    "</div>");
                 }
             }
         }
	    %>
	    <div id="views">
		<strong><%
                    if (Model.viewCount == null)
                    {
                        Response.Write("0");
                    }
                    else
                    {
                        Response.Write(Model.viewCount);
                    }      
                %></strong> áhorf
	    </div><br clear="all" />
	    
<%--	    <div id="series">
		<a href="/Station/AddVideo/<%= (Model.id) %>">Benda <%= (Model.name) %> á myndband. </a>
        </div>--%>
	   
	</div>
	<div id="info">
	    <div id="description" class="clickpop">
		<h3><a href="#" class="click">Upplýsingar um myndbandið</a></h3>
		<p class="popdown"><%= (currentVideo == null ? "" : currentVideo.description) %></p>
	    </div>
	    <div id="comments" class="clickpop">
		<h3><a href="#" class="click">Athugasemdir</a></h3>
		<div class="popdown">
		    <form action="/Home/MakeComment/<%= (currentVideo.id) %>" method="post">
		        <input type="text" id="comment" name="comment" class="text" />
		        <input type="submit" value="Skrá" class="btn" />
		    </form>
<%
    List<Comment> comment = currentVideo.Comments.ToList();
    if (comment != null)
    {
    %>
                <table>
                <tr>
                    <th>Atugasemdir</th>
                    <th>Notendanafn</th>
                    <th>Dagssetning</th>
                </tr>
            
            <%
            foreach (Comment c in comment)
            {
                Response.Write("<tr>");
                Response.Write("<td>" + c.comment1 + "</td><td>" + c.WebUser.username + "</td><td>" + c.commentTime + "</td>");
                Response.Write("</tr>");
            }
        }

    else
        Response.Write("Ekkert comment!");

                    %>
    </table>
		</div>
	    </div>
	    <div id="AddVideo" class="clickpop">
		<h3><a href="/Station/AddVideo/<%= (Model.id) %>">
		<% 
            string message = "Benda " + Model.name + " á myndband.";
            if (user != null)
            {
                foreach (WebUserRole role in user.WebUserRoles)
                {
                    if (role.access >= 1 && role.Station_id == Model.id)
                    {
                        message = "Setja inn myndband.";
                    }
                }
            }
            Response.Write(message);    
		    
                 %></a></h3>                 
		<%--<p class="popdown"><%= (currentVideo == null ? "" : currentVideo.description) %></p>--%>
	    </div>
	</div>
    </div>
    <div id="related">
    
    <h3>Lýsing á stöð</h3>
    
    <%=Html.Encode(Model.description) %>
    
    <br />
    <div>
    <h3>Stjórnendur</h3>
    <%
        List<WebUserRole> roles = Model.WebUserRoles.ToList();
        foreach (WebUserRole role in roles)
        {
            Response.Write("<a href='/Account/Profile/" + role.WebUser.id + "'>" + role.WebUser.username + "</a><br>");
        }
        
        %>
        </div>
        <div>
        <h3>Vinsælustu þættirnir á stöðinni</h3>
        <table>
        <tbody>
        <%foreach (Video v in ViewData["MostPopVideosOnStation"] as List<Video>)
          {%>
          <tr>
          <td><%
              string popularVideo = v.name;
              %><%= Html.ActionLink(popularVideo, "Watch/" + v.id, "Home")%>
              </td>
              </tr>
          <%} %>
          </tbody>
        </table>
        </div>
        -<br />
        <div>       
        
            <h3>Dagskrá</h3>
            <table>
                <tr>
                    <th></th>
                    <th></th>
                </tr>
                
                <%
                    foreach (ScheduleItem si in ViewData["TodaysSchedule"] as List<ScheduleItem>)
                    {
                        Response.Write("<tr><td><img src='" + StationService.GetVideoThumbnail(si.Video_id) + "' /></td>" +
                                        "<td><a href='/Home/Watch/" + si.Video_id + "'>" + si.Video.name + "</a><br />" + si.airDateTime.ToString() + "</td></tr>");
                    }
                 %>
            </table>
         </div>
         </div>

</asp:Content>
